package com.itheima.service.impl;

import com.itheima.entity.ActReDeployment;
import com.itheima.dao.ActReDeploymentDao;
import com.itheima.service.ActReDeploymentService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * (ActReDeployment)表服务实现类
 *
 * @author makejava
 * @since 2022-01-16 15:48:50
 */
@Service("actReDeploymentService")
public class ActReDeploymentServiceImpl implements ActReDeploymentService {
    @Resource
    private ActReDeploymentDao actReDeploymentDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id_ 主键
     * @return 实例对象
     */
    @Override
    public ActReDeployment queryById(String id_) {
        return this.actReDeploymentDao.queryById(id_);
    }

    /**
     * 分页查询
     *
     * @param actReDeployment 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<ActReDeployment> queryByPage(ActReDeployment actReDeployment, PageRequest pageRequest) {
        long total = this.actReDeploymentDao.count(actReDeployment);
        return new PageImpl<>(this.actReDeploymentDao.queryAllByLimit(actReDeployment, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param actReDeployment 实例对象
     * @return 实例对象
     */
    @Override
    public ActReDeployment insert(ActReDeployment actReDeployment) {
        this.actReDeploymentDao.insert(actReDeployment);
        return actReDeployment;
    }

    /**
     * 修改数据
     *
     * @param actReDeployment 实例对象
     * @return 实例对象
     */
    @Override
    public ActReDeployment update(ActReDeployment actReDeployment) {
        this.actReDeploymentDao.update(actReDeployment);
        return this.queryById(actReDeployment.getId_());
    }

    /**
     * 通过主键删除数据
     *
     * @param id_ 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(String id_) {
        return this.actReDeploymentDao.deleteById(id_) > 0;
    }
}
